package demo3;
public class Test {
    public static void main1(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();

        String[] shapes = {"cycle", "rect", "cycle", "rect", "flower"};
        for (String shape:shapes) {
            if(shape.equals("cycle")){
                cycle.draw();
            }else if(shape.equals("rect")){
                rect.draw();
            }else if(shape.equals("flower")){
                flower.draw();
            }
        }
    }

    public static void main(String[] args) {
        /*Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        Triangle triangle = new Triangle();

        Shape[] shapes = {cycle,rect,cycle,rect,flower,triangle};
        for (Shape shape:shapes) {
            shape.draw();
        }*/

        // 向上转型
        Shape[] shapes = {new Cycle(),new Rect(),new Cycle(),
                new Rect(),new Flower(),new Triangle()};
        for (Shape shape:shapes) {
            shape.draw();
        }
    }
}
